package com.op.parcel.manage.modules.sys.wrapper;

import com.op.parcel.boot.support.BaseEntityWrapper;
import com.op.parcel.manage.modules.sys.entity.Role;
import com.op.parcel.manage.modules.sys.entity.User;
import com.op.parcel.manage.modules.sys.service.IRoleService;
import com.op.parcel.manage.modules.sys.vo.UserVO;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * 包装类,返回视图层所需的字段
 *
 * @author xuan
 * @since 2019-01-07
 */
@AllArgsConstructor
public class UserWrapper extends BaseEntityWrapper<User, UserVO> {

	IRoleService roleService;

	@Override
	public UserVO entityVO(User user) {
		UserVO userTarget = new UserVO();
		BeanUtils.copyProperties(user, userTarget);
		userTarget.setPassword(null);
		List<Role> byUserId = roleService.findByUserId(userTarget.getId());
		userTarget.setRoles(byUserId);
		return userTarget;
	}

}
